function MI() {
    this.cs = new CSInterface();
}
// 加载jsx
MI.prototype.loadJSX = function(fileName) {
    var extensionRoot = this.cs.getSystemPath(SystemPath.EXTENSION) + "/hexing/";
    this.cs.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
}
// 创建图层
MI.prototype.creatLayer = function(name) {
    this.cs.evalScript("creatLayer('" + name + "')");
}
// 创建盒型刀模图
MI.prototype.createHx = function(heTypeID, cs) {
    if(heTypeID > 0) {
        this.loadJSX('hexing' + heTypeID + '.jsx');
        this.cs.evalScript('hexing'+heTypeID+'('+cs.L+','+cs.W+','+cs.H+','+cs.T+','+cs.JN+','+cs.JL+','+cs.JW+','+cs.JD+','+cs.JI +',0.5)', function (result) {
            return result;
        });
    } else {
        return false;
    }
}

// 右上角菜单
MI.prototype.flyoutMenu = function() {
    var menuXML = `
    <Menu>
        <MenuItem Id="flyoutMenu1" Label="刷新" Enabled="true" Checked="false" />
        <MenuItem Label="---" />
        <MenuItem Id="flyoutMenu2" Label="软件主页" Enabled="true" Checked="false"/>
    </Menu>
    `;
    this.cs.setPanelFlyoutMenu(menuXML, this.flyoutMenuCallback);
    this.cs.addEventListener("com.adobe.csxs.events.flyoutMenuClicked", this.flyoutMenuCallback);
}
// 右上角菜单回调函数
MI.prototype.flyoutMenuCallback = function(event) {
    if (event.type === "com.adobe.csxs.events.flyoutMenuClicked" &&
        event.extensionId === "com.ateng.wanxiaohe") {
        // 刷新
        if (event.data.menuId == 'flyoutMenu1') {
            location.reload(true);
        } else if (event.data.menuId == 'flyoutMenu2') {
            $mi.openURL("https://gitee.com/atengs/wanxiaohe");
        }
    }
}
// 浏览器打开URL
MI.prototype.openURL = function(url) {
    this.cs.openURLInDefaultBrowser(url);
}
window.$mi = new MI();
$mi.flyoutMenu();